home *** CD-ROM | disk | FTP | other *** search
- Path: io.UWinnipeg.ca!wsimpson
- From: Bill Simpson <wsimpson@uwinnipeg.ca>
- Newsgroups: comp.lang.c
- Subject: swap high and low 16 bits?
- Date: Mon, 15 Jan 1996 17:55:15 -0600
- Organization: The University of Manitoba
- Message-ID: <Pine.OSF.3.91.960115174921.19742A-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: io.uwinnipeg.ca
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
-
- I wanted to obtain a "random" starting number each time a program
- is run. The obvious choice is time(NULL). The problem with it is that
- if the program runs and terminates fairly quickly, the number returned by
- time(NULL) is quite similar each run, differing only by the lowest bits.
-
- One solution would be to swap the high 16 bits and the low 16 bits of the
- 32 bit unsigned long int. Sorry this is dirty, not ANSI.
-
- Could anyone please tell me how to do this? The simpler the code the
- better (ANSI not important for this particular case).
-
- Other solutions to the general problem (e.g. rotating the low bits to
- the high end) are welcome.
-
- Thanks very much for any help.
-
- Bill Simpson
-